package com.icss.lesson4;

public class TestMain1 {
    public static void main(String[] args) {
        Thread t1 = new Aaaa("线程1");
        Aaaa t2 = new Aaaa("线程2");
        // 局部匿名内部类
        new Thread(new Runnable() {
            @Override
            public void run() {
                // 任务
                for (int i = 0; i < 100; i++) {
                    if (i == 60) {

                        try {

                            Thread.sleep(2000);
                            System.out.println("=========================");
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }

                    }

                    System.out.println(Thread.currentThread() + "@" + i);
                }
            }
        }, "线程三").start();

        // 局部匿名内部类  Lambda表达式
        new Thread(() -> {
                // 任务
                for (int i = 0; i < 100; i++) {
                    if (i == 60) {
                        try {
                            Thread.sleep(2000);
                            System.out.println("=========================");
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    System.out.println(Thread.currentThread() + "@" + i);
                }
        }, "线程四").start();

        t1.start();
        t2.start();
    }
}
class Aaaa extends Thread {
    public Aaaa() {
    }

    public Aaaa(String name) {
        super(name);
    }

    @Override
    public void run() {
        // 任务
        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread() + "@" + i);
        }
    }
}
